home *** CD-ROM | disk | FTP | other *** search
- /* #include files */
- #include <Types.h>
- #include <Memory.h>
- #include <Quickdraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Menus.h>
- #include <Windows.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
- #include <OSUtils.h>
- #include <ToolUtils.h>
- #include <TextUtils.h>
- #include <SegLoad.h>
- #include <Sound.h>
-
- /* #defines */
- #define kQuitDialogResId 128
- #define kPopupMenuResId 128
-
- #define kOkButton 1
- #define kCancelButton 2
- #define kPopupMenu 3
- #define kAlertIcon 4
- #define kPromptString1 5
- #define kPromptString2 6
-
- //#define kTestString1 "\pThere is not enough memory to open "
- //#define kTestString2 "\pSelect one or more applications to quit from the list below. Then click \"Quit Applications\" to reopen \""
-
- #define kThisAppSig 'ASd0'
-
- #define kErrorALRTid 128
-
- #define kNoIdleProc nil
- #define kNoFilterProc nil
-
- /* Constants */
-
- /* Types */
-
- /* Globals */
-
- /* Prototypes */
- void Initialize( void );
- void HandleDialog( void );
- void SendAppleEvent( long targetSignature );
- //pascal Boolean OurFilter( DialogPtr dlg, EventRecord *event, short *itemHit );
-
- int main( void ) {
- Initialize();
-
- HandleDialog();
-
- return 0;
- }
-
- void Initialize( void ) {
- InitGraf( &qd.thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( nil );
- InitCursor();
-
- FlushEvents( everyEvent, 0 );
- }
-
- void HandleDialog( void ) {
- DialogPtr theDialog;
- DialogItemIndex itemHit = -1;
- Boolean result = false;
- GrafPtr oldPort;
- DialogItemType itemType;
- Handle item;
- Rect box;
- MenuHandle theMenu = nil;
- ProcessSerialNumber thePSN;
- ProcessInfoRec info;
- FSSpec processFSSpec;
- long menuSelection = -1;
- Str255 processName, tempName, matchName;
- short itemCount = 1, i = 0, j = 0;
- CharParameter markChar;
- SInt16 theItem;
- Style getStyle;
-
- theDialog = ( DialogPtr )GetNewDialog( kQuitDialogResId, 0L, ( WindowPtr )-1L );
-
- if ( theDialog == nil )
- return;
-
- theMenu = GetMenu( kPopupMenuResId );
-
- if ( theMenu == nil )
- goto cleanup;
-
- GetPort( &oldPort );
- SetPort( theDialog );
-
- SetDialogDefaultItem( theDialog, ok ) ;
-
- // GetDialogItem( theDialog, kPromptString1, &itemType, &item, &box );
- // SetDialogItemText( item, kTestString1 );
-
- HLock( ( Handle )theMenu );
-
- // check the current processes to see if the application is already
- // running, and get its process serial number.
- thePSN.lowLongOfPSN = kNoProcess;
- thePSN.highLongOfPSN = 0;
-
- info.processInfoLength = sizeof( FSSpec );
- info.processName = ( unsigned char * )processName;
- info.processAppSpec = &processFSSpec;
-
- while ( noErr == GetNextProcess( &thePSN ) ) {
- if ( noErr == GetProcessInformation( &thePSN, &info ) ) {
- if ( info.processType == 'APPL' && info.processSignature != kThisAppSig ) {
- AppendMenu( theMenu, info.processName );
- }
- }
- }
-
- SetControlValue( ( ControlHandle )theMenu, 1 );
- Draw1Control( ( ControlHandle )theMenu );
-
- do {
- ModalDialog( 0L, &itemHit );
-
- if ( itemHit == kPopupMenu ) {
- // get the control handle for the popup
- GetDialogItem( theDialog, kPopupMenu, &itemType, &item, &box ) ;
- theItem = GetControlValue( ( ControlHandle )item );
- GetItemMark( theMenu, theItem, &markChar );
-
- GetMenuItemText( theMenu, theItem, tempName );
-
- j = tempName[ 0 ];
-
- GetItemStyle( theMenu, theItem, ( unsigned char * )&getStyle );
-
- if ( getStyle == bold ) {
- SetItemStyle( theMenu, theItem, normal );
- }
- else {
- SetItemStyle( theMenu, theItem, bold );
- }
-
- // this ensures that the update handler in the filter proc is called
- // as that is where we enable or disable the OK button
- InvalRect( &box ) ;
-
- // reset itemHit to something else or we'll continually redraw
- itemHit = 0;
- }
- } while ( itemHit != ok && itemHit != cancel );
-
- if ( itemHit != ok )
- goto cleanup;
-
- itemCount = CountMItems( theMenu );
-
- for ( i = 1; i <= itemCount; i++ ) {
- GetDialogItem( theDialog, kPopupMenu, &itemType, &item, &box );
-
- GetMenuItemText ( theMenu, i, matchName );
-
- GetItemStyle( theMenu, i, ( unsigned char * )&getStyle );
-
- if ( getStyle != bold )
- continue;
-
- thePSN.lowLongOfPSN = kNoProcess;
- thePSN.highLongOfPSN = 0;
-
- info.processInfoLength = sizeof( FSSpec );
- info.processName = ( unsigned char * )processName;
- info.processAppSpec = &processFSSpec;
-
- while ( noErr == GetNextProcess( &thePSN ) ) {
- if ( noErr == GetProcessInformation( &thePSN, &info ) ) {
- if ( info.processType == 'APPL' && info.processSignature != kThisAppSig ) {
- j = 0;
-
- while ( j <= info.processName[ 0 ] ) {
- tempName[ j ] = info.processName[ j ];
- j++;
- }
-
- tempName[ 0 ] = info.processName[ 0 ];
-
- if ( EqualString( tempName, matchName, false, false ) ) {
- SendAppleEvent( info.processSignature );
- break;
- }
- }
- }
- }
- }
-
- cleanup:
- HUnlock( ( Handle )theMenu );
-
- DisposeDialog( theDialog );
-
- SetPort( oldPort );
- }
-
- void SendAppleEvent( long targetSignature ) {
- AEAddressDesc targetAddrDesc = {typeNull, nil};
- AppleEvent event = {typeNull, nil};
- AppleEvent reply = {typeNull, nil};
- OSErr err;
-
- err = AECreateDesc( typeApplSignature, (Ptr)(&targetSignature),
- sizeof( targetSignature ), &targetAddrDesc );
-
- if ( err != noErr )
- goto cleanup;
-
- err = AECreateAppleEvent( kCoreEventClass, kAEQuitApplication,
- &targetAddrDesc, kAutoGenerateReturnID,
- kAnyTransactionID, &event );
-
- if ( err != noErr )
- goto cleanup;
-
- err = AESend( &event, &reply, kAENoReply,
- kAENormalPriority, kAEDefaultTimeout, kNoIdleProc, kNoFilterProc );
-
- cleanup:
- AEDisposeDesc (&targetAddrDesc);
- AEDisposeDesc (&event);
- AEDisposeDesc (&reply);
- }
-
-